<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表格渲染</title>
</head>
<body>
    <table cellspacing="0" border="1" width="300px">
        <thead>
          <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>性别</th>
          </tr>
        </thead>
      </table>
      <script>
        var userList = [
          { id: 1, name: 'Jack', age: 18, gender: '男' },
          { id: 2, name: 'Rose', age: 20, gender: '女' },
          { id: 3, name: 'Tom', age: 22, gender: '男' },
          { id: 4, name: 'Jerry', age: 24, gender: '女' },
        ];
        var table = document.querySelector("table");
        var tbody = document.createElement("tbody");
        tbody.style.textAlign = "center";
        table.append(tbody);
        userList.forEach(function (e) {
            // console.log(e);
            var tr = document.createElement("tr");
            tbody.append(tr);
            for(var key in e){
                var td = document.createElement("td");
                td.textContent = e[key];
                // console.log(e[key]);
                tr.append(td);
            }
        });
      </script>
</body>
</html>